package com.kgc.scd.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.bean.ProductVO;
import com.kgc.scd.service.AddFootService;
import com.kgc.scd.service.ProductServiceFeign;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.UserAnno;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: WangKuoKuo
 * @create: 2022-06-14 15:27
 * @description:
 **/

@RestController
@Api(tags = "10、商品详情入口")
public class ProductWebController {
    @Autowired
    private ProductServiceFeign productServiceFeign;
    @Autowired
    private AddFootService addFootService;
    /**
     * @author : WangKuoKuo
     * @date   : 2022/6/14/014
     * @param  : [proId]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.bean.ProductVO>
     * @description : 根据商品id查询商品
     */
    @GetMapping("/list")
    @ApiOperation("根据商品id查询商品")
    @RequestPermission
    @ApiImplicitParam(name = "proId", value = "商品id")
    RequestResult<ProductVO> listProduct(@RequestParam String proId,
                                         @RequestUser UserAnno userAnno){
        addFootService.requestFoot(userAnno.getUserId(),proId);
        return productServiceFeign.listProduct(proId);
    }

    @GetMapping("/commentPage")
    @ApiOperation("商品评论分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commProId", value = "商品id"),
            @ApiImplicitParam(name = "pageNo", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数"),
            @ApiImplicitParam(name = "orderBy", value = "排序 0:按照评论时间升序，1：降序"),
            @ApiImplicitParam(name = "commentLevel", value = "评价级别 1：好评 2：中评 3：差评",defaultValue = "1")
    })
        public RequestResult<Page> listComment(@RequestParam String commProId,
                                               @RequestParam(value = "pageNo",defaultValue = "1")  Integer pageNo,
                                               @RequestParam(value = "pageSize",defaultValue = "6")  Integer pageSize,
                                               @RequestParam(value ="orderBy", defaultValue = "0") Integer orderBy,
                                               @RequestParam(value ="commentLevel", defaultValue = "1") Integer commentLevel) {
        return productServiceFeign.listComment(commProId,pageNo,pageSize,orderBy,commentLevel);
    }

}
